/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.srm.entidades;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author TilZon
 */
@Entity
@DiscriminatorValue("USUARIO")
@Table(name = "usuario", catalog = "srmdb", schema = "")
@PrimaryKeyJoinColumn(name = "id_usuario", referencedColumnName = "id")
public class Usuario extends Persona implements Serializable {

    @Basic(optional = false)
    @Column(name = "login")
    private String login;
    @Lob
    @Column(name = "clave")
    private String clave;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "usuario")
    private List<Pago> pagos;

    @OneToOne(fetch=FetchType.EAGER)
    @JoinColumn(name="id_empresa")
    private Empresa empresa;

    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(name="user_rol",
          joinColumns=@JoinColumn(name="user_id"),
          inverseJoinColumns=@JoinColumn(name="rol_id"))
    private List<Rol> roles;

    public Usuario() {
        this.roles=new ArrayList<Rol>();
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getClave() {
        return clave;
    }

    public void setClave(String clave) {
        this.clave = clave;
    }


    public Empresa getEmpresa() {
        return empresa;
    }

    public void setEmpresa(Empresa empresa) {
        this.empresa = empresa;
    }

    public List<Pago> getPagos() {
        return pagos;
    }

    public void setPagos(List<Pago> pagos) {
        this.pagos = pagos;
    }

    public List<Rol> getRoles() {
        return roles;
    }

    public void setRoles(Rol rol) {
         if(getRoles()!=null)
        {
         if (!getRoles().contains(rol)) {
            this.roles.add(rol);
        }
        }
        else
        {
         this.roles.add(rol);
        }
    }

}
